package com.qingneng.budget.web;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;
import com.qingneng.budget.service.sdk.IProjectInfoService;
import com.qingneng.budget.util.BaseAction;
import com.qingneng.budget.vo.ProjectWorkInfo;


public class SaveProjectWorkInfoChildAction extends BaseAction implements ModelDriven<ProjectWorkInfo> {
	
	private static final Logger logger = Logger.getLogger(SaveProjectWorkInfoChildAction.class);

	// init service
	private IProjectInfoService projectInfoService;
	
    private String message = null;
    
    private ProjectWorkInfo projectWorkInfo = new ProjectWorkInfo() ;
    
	
	public ProjectWorkInfo getProjectWorkInfo() {
		return projectWorkInfo;
	}

	public void setProjectWorkInfo(ProjectWorkInfo projectWorkInfo) {
		this.projectWorkInfo = projectWorkInfo;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	// 构造函数
	public SaveProjectWorkInfoChildAction(IProjectInfoService projectInfoService) {
		this.projectInfoService = projectInfoService;
	}

	public SaveProjectWorkInfoChildAction() {

	}
	
	public String save(){
		if(logger.isDebugEnabled()){
			logger.debug("+++ begin save projectWorkInfo execute +++");
		}
		try {
			logger.info("Projectinfo_id:"+projectWorkInfo.getProjectinfo_id());
			
			int id = projectWorkInfo.getId();
			if(id==0){
				projectInfoService.addProjectWorkChildInfo(projectWorkInfo);
			}else{
				projectInfoService.modifyProjectWorkChildInfo(projectWorkInfo);
			}			
		//	projectWorkInfo.setId(1);
			message = "success";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(logger.isDebugEnabled()){
			logger.debug("+++ end save projectWorkInfo execute +++");
		}
		return Action.SUCCESS;
	}
	
	
	public String destroy(){
		if(logger.isDebugEnabled()){
			logger.debug("+++ begin destroy projectWorkInfo execute +++");
		}
		try {
			logger.info("ProjectWorkinfo_id:"+projectWorkInfo.getId());
			projectInfoService.destroyProjectWorkChildInfo(projectWorkInfo);
			message = "success";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(logger.isDebugEnabled()){
			logger.debug("+++ end destroy projectWorkInfo execute +++");
		}
		return Action.SUCCESS;
	}
	
	
	

	public ProjectWorkInfo getModel() {
		// TODO Auto-generated method stub
		return projectWorkInfo;
	}
	
	
}
